﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Game.Types;

namespace GameEditor2.Toolbox
{
    public partial class StandardTerrainItemControl : UserControl
    {
        IMapItemType _MapItemType;
        
        public StandardTerrainItemControl()
        {
            InitializeComponent();
            
            SelectedMapItemType.Selected += delegate 
            {
                this.UpdatePressedState();
            };
        }
        
        public Brush ToolColor
        {
            get { return this.button.Background; }
            set { this.button.Background=value; }
        }
        
        public IMapItemType MapItemType
        {
            get { return _MapItemType; }
            set { _MapItemType = value; DisplayType(); }
        }
        
        void DisplayType()
        {
            if (_MapItemType != null)
            {
                BitmapImage image = new BitmapImage();
                image.BeginInit();
                image.StreamSource = _MapItemType.Picture.Stream;
                image.EndInit();
                this.buttonImage.Source = image;
            }
        }
        
        void Button_Click(object sender, RoutedEventArgs e)
        {
            SelectedMapItemType.MapItemType = _MapItemType;
        }
        
        void UpdatePressedState()
        {
            if (SelectedMapItemType.MapItemType == _MapItemType)
            {
                this.button.Background=SystemColors.HighlightBrush;
            }
            else
            {
                this.button.Background=SystemColors.ControlLightBrush;
            }
        }
    }
}